package com.fingard.dsp.bank.directbank.bob11;

import com.fingard.dsp.bank.directConfig.FtpSet;
import com.fingard.dsp.bank.directbank.DirectBase;
import com.fingard.net.ConnState;
import com.fingard.net.FtpPortClient;
import com.fingard.net.FtpReceiver;
import com.fingard.text.StringHelper;

import java.io.IOException;

public class BOB11Base extends DirectBase {
    protected String getCharset() {
        return getBankConfig().getCharset("GBK");
    }



    public FtpReceiver sendToBank(String deFilePath, String sumFilePath,String deFileName,String sumFileName, String tmpUploadFiledir) {
        FtpSet ftpSet = bankFront.getFtpSet("bat");
        FtpReceiver ftpReceiver = null;
        FtpPortClient ftpPortClient = null;
        try {
            ftpPortClient = new FtpPortClient(ftpSet);
            String ftpFilePath = StringHelper.trimEnd(ftpSet.upDir, "/") + "/" + tmpUploadFiledir;
            WriteBankLogLn("FTP服务器文件路径:" + ftpFilePath);
            WriteBankLogLn2("FTP服务器文件上传地址:" + ftpSet.serverIP + ":" + ftpSet.port);
            //FTP设置成被动模式
            ftpPortClient.setLocalPassiveMode();
            ftpReceiver = ftpPortClient.uploadFileToDir(deFilePath,ftpFilePath, deFileName);
            if (ftpReceiver.isCompleted) {
                ftpPortClient.deleteFile(ftpFilePath + "/"+sumFileName);
                ftpReceiver=ftpPortClient.uploadFileToDir(sumFilePath,ftpFilePath, sumFileName);
                ftpPortClient.disconnect();
                WriteBankLogLn("明细文件上传成功");
            } else if (ConnState.FAIL.equals(ftpReceiver.connState)) {
                WriteBankLogLn("明细文件上传失败");
            } else {
                WriteBankLogLn("明细文件上传失败，失败原因："+ftpReceiver.connMsg);
            }
           } catch (Exception e) {
            if (ftpPortClient != null) {
                try {
                    ftpPortClient.disconnect();
                } catch (IOException ie) {
                    e.printStackTrace();
                    WriteBankLogLn(ie);
                }
            }
        }
        return ftpReceiver;
    }
}